((window) => {
    const PENDING = "pending";
    const FULFILLED = "fulfilled";
    const REJECTED = "rejected";
    /** 
* @parm excutor
*/


    function Promise(excutor) {
        this.state = PENDING;
        this.data = undefined;
        this.callbacks = [];
        const self = this;

        function resolved(value) {
            if (self.state !== PENDING) return

            self.state = FULFILLED
            self.data = value

            if (self.callbacks.length > 0) {
                setTimeout(() => {
                    self.callbacks.forEach(callbackObj => callbackObj.resolved(value))
                }, 0)
            }
        }
        try {
            excutor(resolve, reject);
        } catch (error) {
            reject(error)
        }

    }

    /**
     *  @parm {*} onResolved
     *  @parm {*} onrejected
     */

    Promise.prototype.then = function (onResolved, onRejected) {
        const self = this
        onResolved = typeof onResolved==="function" ? onResolved : value =>value
        onReject = typeof onRejected==="function" ? onRejected : reason => {throw reason}

        return new Promise ((resolve, reject) => {
            function handle(callback) {
                try {
                    const result = callback(self.data)
                    
                }
            }
        })
    }



})

